package org.dromara.answer.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Select;
import org.dromara.answer.domain.AiUserExams;
import org.dromara.answer.domain.vo.AiUserExamsVo;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;

import java.util.List;

/**
 * 用户考试记录Mapper接口
 *
 * @author Lion Li
 * @date 2025-04-09
 */
public interface AiUserExamsMapper extends BaseMapperPlus<AiUserExams, AiUserExamsVo> {

    /**
     * 查询用户考试记录列表，包含用户昵称和考试标题
     */
    @Select("SELECT ue.*, u.nick_name, e.title as exam_title " +
            "FROM ai_user_exams ue " +
            "LEFT JOIN sys_user u ON ue.user_id = u.user_id " +
            "LEFT JOIN ai_exams e ON ue.exam_id = e.exam_id " +
            "ORDER BY ue.create_time DESC")
    List<AiUserExamsVo> selectVoListWithDetails();

    /**
     * 分页查询用户考试记录列表，包含用户昵称和考试标题
     */
    @Select("SELECT ue.*, u.nick_name, e.title as exam_title " +
            "FROM ai_user_exams ue " +
            "LEFT JOIN sys_user u ON ue.user_id = u.user_id " +
            "LEFT JOIN ai_exams e ON ue.exam_id = e.exam_id " +
            "ORDER BY ue.create_time DESC")
    Page<AiUserExamsVo> selectVoPageWithDetails(Page<AiUserExamsVo> page);

    /**
     * 根据ID查询用户考试记录，包含用户昵称和考试标题
     */
    @Select("SELECT ue.*, u.nick_name, e.title as exam_title " +
            "FROM ai_user_exams ue " +
            "LEFT JOIN sys_user u ON ue.user_id = u.user_id " +
            "LEFT JOIN ai_exams e ON ue.exam_id = e.exam_id " +
            "WHERE ue.user_exam_id = #{userExamId}")
    AiUserExamsVo selectVoByIdWithDetails(Long userExamId);
}
